﻿using AnQinFrameWorkAPI.Entity.BaseInfo.DTO.Department;
using AnQinFrameWorkAPI.Entity.BaseInfo.View.Department;
using AnQinFrameWorkAPI.Service.BaseInfo;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.BaseInfo;

/// <summary>
///     部门API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "BaseInfo")]
public class DepartmentController : ControllerBase
{
    //业务接口
    private readonly DepartmentService _departmentService;

    //构造注入
    public DepartmentController(DepartmentService departmentService)
    {
        _departmentService = departmentService;
    }

    /// <summary>
    ///     获取部门列表
    /// </summary>
    [ProducesResponseType(typeof(DepartmentView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetDepartmentList([FromQuery] DepartmentSearchDTO departmentSearchDTO)
    {
        var response = await _departmentService.GetDepartmentList(departmentSearchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增部门
    /// </summary>
    /// <params name="departmentAddDTO"></params>
    [HttpPost]
    public async Task<IActionResult> AddDepartment([FromBody] DepartmentAddDTO departmentAddDTO)
    {
        var response = await _departmentService.AddDepartment(departmentAddDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     编辑部门
    /// </summary>
    /// <params name="departmentUpdateDTO"></params>
    [HttpPut]
    public async Task<IActionResult> PutDepartment([FromBody] DepartmentUpdateDTO departmentUpdateDTO)
    {
        var response = await _departmentService.PutDepartment(departmentUpdateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除部门
    /// </summary>
    [HttpDelete]
    public async Task<IActionResult> DeleteDepartment([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _departmentService.DeleteDepartment(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     获取部门侧边列表
    /// </summary>
    [ProducesResponseType(typeof(DepartmentView), 200)]
    [HttpGet("Aside")]
    public async Task<IActionResult> GetDepartmentAsideList(
        [FromQuery] DepartmentAsideSearchDTO departmentAsideSearchDTO)
    {
        var response = await _departmentService.GetDepartmentListAside(departmentAsideSearchDTO);
        return StatusCode(response.Status, response);
    }
}